package account.docent.controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.UnknownHostException;

import javax.swing.JList;

import dao.server.DataLoadIP;
import account.model.SubTeam;
import account.model.HelpListModel;
import account.model.InloggenModel;
import prototyping.client.AbstractMessage;
import prototyping.client.HelpMessage;
import prototyping.client.student.model.StudentClient;
import prototyping.client.teacher.model.TeacherClient;
import tools.language.MentionAccounts;
import tools.language.MentionChat;

public class AfhandelController implements ActionListener {

	HelpListModel hlModel;
	JList<AbstractMessage> jList;
	TeacherClient tc;

	public AfhandelController(JList<AbstractMessage> jl, String userName, String server) {
		hlModel = (HelpListModel) jl.getModel();
		jList = jl;

		tc = new TeacherClient(server, userName);
		tc.start();
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		HelpMessage hmsg;
		hmsg = (HelpMessage)jList.getSelectedValue();
		//handel vragen van studenten af
		if ("Afgehandeld".equals(e.getActionCommand())) {
			//foutmelding indien geen item geslecteerd is
			if(jList.isSelectionEmpty()){
				MentionChat.getInstance().errorList();
			} else {
				//verwijder item van lijst en server
				hmsg.setDone(true);
				tc.sendMessage(hmsg);
				hlModel.deleteMessage(jList.getSelectedValue());
			}
		}
	}
}